﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Renci.iRods.Common;

namespace Renci.iRods.Data
{

    public class MetaData
    {
        private int _initHashcode;

        public long ID { get; private set; }

        public string Namespace { get; private set; }

        public string Name { get; set; }

        public string Value { get; set; }

        public string Unit { get; set; }

        internal string OldName { get; private set; }

        internal string OldValue { get; private set; }

        public bool IsDirty
        {
            get
            {
                return this.ID == 0 || this._initHashcode != this.GetHashCode();
            }
        }

        internal MetaData(int id, string namespaceName, string name, string value, string unit)
        {
            this.ID = id;
            this.Namespace = namespaceName;
            this.OldName = this.Name = name;
            this.OldValue =  this.Value = value;
            this.Unit = unit;
            this._initHashcode = this.GetHashCode();
        }

        internal MetaData(int id, string name, string value, string unit)
            : this(id, null, name, value, unit)
        {
        }
        
        public MetaData(string name, string value)
            : this(0, null, name, value, null)
        {
        }

        public MetaData(string name, string value, string unit)
            : this(0, null, name, value, unit)
        {
        }

        public MetaData(string name, string namespaceName, string value, string unit)
            : this(0, namespaceName, name, value, unit)
        {
        }

        public override int GetHashCode()
        {
            return string.Format("{0}:{1}:{2}:{3}:{4}", this.ID, this.Namespace, this.Name, this.Value, this.Unit).GetHashCode();
        }
    }
}
